package linguistic;

import java.util.ArrayList;
import java.util.List;

import sets.IFuzzySet;
import universe.IUniverseOfDiscourse;

/**
 * Representation of Linguistic Variable
 * @author Adam Taciak
 *
 */
public class Variable {
	private String name;
	private String column;
	private List<String> labels;
	private IUniverseOfDiscourse universe;
	private List<IFuzzySet> sets;
	private List<Boolean> active;
	
	public Variable() {
		labels = new ArrayList<>();
		sets = new ArrayList<>();
		active = new ArrayList<>();
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void setColumn(String column) {
		this.column = column;
	}
	
	public String getColumn() {
		return column;
	}
	
	public String getName() {
		return name;
	}
	
	public void setUniverse(IUniverseOfDiscourse universe) {
		this.universe = universe;
	}
	
	public void addFuzzySet(String label, IFuzzySet set, boolean isActive) {
		// Display warring that universe of discourse or column from database related with set
		//   wasn't yet defined for linguistic variable
		if (universe == null) {
			System.out.println("Warning! Universe Of Discourse for linguistinc variable hasn't been defined!");
		}
		if (column == null) {
			System.out.println("Warning! Column for linguistic variable hasn't been defined!");
		}
		
		labels.add(label);
		sets.add(set);
		active.add(isActive);
		
		// Modify universe of discourse in set
		if (universe != null) {
			set.setUniverseOfDiscorse(universe);
		}
		
		// Modify column which is related with this set
		if (column != null) {
			set.setColumn(column);
		}
	}
	
	public List<IFuzzySet> getFuzzySets() {
		return sets;
	}
	
	public List<String> getLabels() {
		return labels;
	}
	
	public List<Boolean> getActive() {
		return active;
	}
	
	/**
	 * Helper method for summaries generator.
	 * @return
	 */
	public int numberOfActiveSets() {
		int n = 0;
		
		for (Boolean a : active) {
			if (a) {
				n++;
			}
		}
		
		return n;
	}
	
	public void show() {
		System.out.println("Linguistic Variable: " + name);
		System.out.println("\thas " + sets.size() + " fuzzy sets:");
		for (int i = 0; i < sets.size(); ++i) {
			System.out.println(i+1 + ": " + labels.get(i));
		}
	}
}
